﻿/*
 * Copyright (c) 2011 Shawn Rakowski
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to 
 * deal in the Software without restriction, including without limitation the 
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 
 * sell copies of the Software, and to permit persons to whom the Software is 
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in 
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
 * SOFTWARE. 
 * 
 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ROS.Presentation.Presenters;
using ROS.Presentation.Views;
using ROS.Presentation.Views.Data;

namespace ROS.UI
{
    public partial class AddMenuItemForm : ROS.UI.BaseForms.BaseDataEntryForm, IAddMenuItemView
    {
        #region Fields

        private List<MenuCategoryViewData> selectedMenuCategories;
        private List<MenuCategoryViewData> selectableMenuCategories;

        #endregion

        #region Properties

        public string MenuItemName
        {
            get
            {
                return nameTextBox.Text;
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public String Price
        {
            get
            {
                return priceTextBox.Text;
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public bool IsBackendFulfilled
        {
            get
            {
                return isBackendFulfilledCheckBox.Checked;
            }
            set
            {
                isBackendFulfilledCheckBox.Checked = value;
            }
        }

        public List<MenuCategoryViewData> SelectedMenuCategories
        {
            get
            {
                return selectedMenuCategories;
            }
            set
            {
                selectedMenuCategories = value;
                LoadSelectedMenuCategoriesListBox();
            }
        }

        public List<MenuCategoryViewData> SelectableMenuCategories
        {
            get
            {
                return selectableMenuCategories;
            }
            set
            {
                selectableMenuCategories = value;
                LoadSelectableMenuCategoriesListBox();
            }
        }

        #endregion

        #region Events

        public event EventHandler LoadView;

        public event EventHandler AddCategory;

        public event EventHandler RemoveCategory;
        
        #endregion

        #region Constructor

        public AddMenuItemForm()
        {
            InitializeComponent();
            new AddMenuItemPresenter(this);
            selectedMenuCategories = new List<MenuCategoryViewData>();
            selectableMenuCategories = new List<MenuCategoryViewData>();
        }

        #endregion

        #region Methods

        public MenuCategoryViewData GetSelectedCategoryFromSelectedCategories()
        {
            return (MenuCategoryViewData)selectedCategoriesListBox.SelectedItem;
        }

        public MenuCategoryViewData GetSelectedCategoryFromSelectableCategories()
        {
            return (MenuCategoryViewData)selectableCategoriesListBox.SelectedItem;
        }

        private void AddMenuItemForm_Load(object sender, EventArgs e)
        {
            if (LoadView != null) { LoadView(sender, e); }
            nameTextBox.Focus();
        }

        private void addCategoryButton_Click(object sender, EventArgs e)
        {
            if (AddCategory != null) { AddCategory(sender, e); }
        }

        private void removeCategoryButton_Click(object sender, EventArgs e)
        {
            if (RemoveCategory != null) { RemoveCategory(sender, e); }
        }

        private void LoadSelectedMenuCategoriesListBox()
        {
            selectedCategoriesListBox.Items.Clear();
            foreach (MenuCategoryViewData menuCategory in selectedMenuCategories)
            {
                selectedCategoriesListBox.Items.Add(menuCategory);
            }
        }

        private void LoadSelectableMenuCategoriesListBox()
        {
            selectableCategoriesListBox.Items.Clear();
            foreach (MenuCategoryViewData menuCategory in selectableMenuCategories)
            {
                selectableCategoriesListBox.Items.Add(menuCategory);
            }
        }

        private void selectableCategoriesListBox_DoubleClick(object sender, EventArgs e)
        {
            addCategoryButton_Click(sender, e);
        }

        private void selectedCategoriesListBox_DoubleClick(object sender, EventArgs e)
        {
            removeCategoryButton_Click(sender, e);
        }

        #endregion
    }
}
